import React from 'react';
import moment from 'moment';
import { Alert } from 'react-native';
import { Scene, Actions, ActionConst } from 'react-native-router-flux';
import Form from './Form';
import CheckCustomer from './checkCustomer';
import store from '../models/home';
import customer from '../../customer/models/customer';
import customers from '../../customer/models/customers';
import navBarStyle from '../../../components/navBarStyle';
// import NavBarIconBtn from '../../../components/NavBarIconBtn';
// import Form from '../../../components/Form';
// import MyForm from './myForm';

const alert = Alert.alert;

const pressHandle = values => {
  values.scheduledTime =
    values.scheduledTime &&
    moment(values.scheduledTime).format('YYYY-MM-DD HH:mm');
  store.addTask(values).then(data => {
    if (data) {
      alert('操作成功', '添加任务', [{ text: '返回', onPress: Actions.pop }]);
    }
  });
};
module.exports = [
  <Scene
    key="checkCustomer"
    component={CheckCustomer}
    path="mission/checkCustomer"
    title="任务目标客户"
    hideTabBar
    onSubmit={pressHandle}
    store={store}
    customer={customer}
    customers={customers}
    onEnter={customers.init.bind(customers)}
    hideNavBar={false}
    {...navBarStyle}
  />,
  /* 
挂参数，并且以replace形式跳转，
需要再目标Scene上使用type="replace"属性，
如果在跳转行为上使用Actions.replace([key], {optiosn})，
目标Scene的附加props将无法获取
*/
  <Scene
    key="editTask"
    component={Form}
    path="mission/add"
    title="新建任务"
    hideTabBar
    onSubmit={pressHandle}
    store={store}
    customer={customer}
    hideNavBar={false}
    {...navBarStyle}
  />
];
